package com.wteam.dragon.shop.controller;

import com.wteam.dragon.shop.search.service.ProductSearch;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.apps.security.annotation.AnonymousAccess;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 陈晓辉
 * @Date 2021/3/27 9:38
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "商品搜索")
@RequestMapping("productSearch")
public class ProductSearchController {
    private final ProductSearch productSearch;

    @Log("导入所有商品")
    @ApiOperation("导入所有商品")
    @GetMapping("importAll")
    @PreAuthorize("@el.check('importAll')")
    public ResultMessage importAll(){
        return productSearch.importAll();
    }

    @Log("添加商品")
    @ApiOperation("添加商品")
    @PostMapping("insert")
    @PreAuthorize("@el.check('insert')")
    public ResultMessage insert(Long id){
        return productSearch.insert(id);
    }

    @Log("根据id删除商品")
    @ApiOperation("根据id删除商品")
    @DeleteMapping("deleteById")
    @PreAuthorize("@el.check('deleteById')")
    public ResultMessage deleteById(Long id){
        return productSearch.deleteById(id);
    }

    @Log("根据id批量删除商品")
    @ApiOperation("根据id批量删除商品")
    @DeleteMapping("deleteByIds")
    @PreAuthorize("@el.check('deleteByIds')")
    public ResultMessage deleteByIds(@RequestParam List<Long> ids){
        return productSearch.deleteByIds(ids);
    }


    @Log("根据关键字搜索")
    @ApiOperation("根据关键字搜索")
    @GetMapping("searchByKeyword")
    @PreAuthorize("@el.check('searchByKeyword')")
    @AnonymousAccess
    public ResultMessage searchByKeyword(String keywords, Integer current, Integer size){
        return productSearch.searchByKeyword(keywords, current, size);
    }



}
